#!/usr/bin/env python
'''Query Wikipedia'''

__author__ = "Miki Tebeka <miki.tebeka@gmail.com>"
__license__ = "BSD" # see LICENSE

import webbrowser

URL = "http://en.wikipedia.org/wiki/Special:Search?search=%s"

def wikipedia(query):
    if isinstance(query, (tuple, list)):
        query = "+".join((item.strip() for item in query if item))

    webbrowser.open(URL % query)

def main(argv=None):
    if argv is None:
        import sys
        argv = sys.argv

    from optparse import OptionParser

    parser = OptionParser("usage: %prog QUERY [QUERY2 ...]")

    opts, args = parser.parse_args(argv[1:])
    if len(args) < 1:
        parser.error("wrong number of arguments") # Will exit

    wikipedia(args)

if __name__ == "__main__":
    main()
